package com.oxygen.education.utils;

import java.util.ArrayList;
import java.util.List;

public class TyyTest {
    public static void main(String[] args) {
        List<String> parentList = new ArrayList<String>();

        for(int i = 0; i < 5; i++){
            parentList.add(String.valueOf(i));
        }

        List<String> subList = parentList.subList(1, 3);
        System.out.println("=================");
        for(String s : subList){
            System.out.print(s);//output: 1, 2
        }
        System.out.println("=================");
        subList.clear();

        System.out.println(parentList.size());//output: 3
        subList = parentList.subList(1, 3);

        // 在subList集合中的元素{1,2}中的第0的位置设置为new 1,即把1设置成了new 1
        subList.set(0, "new 1");
        System.out.println("=================");
        for(String s : parentList){
            System.out.print(s);//output: 0, new 1, 2, 3, 4
        }
        System.out.println("=================");
        subList.add(String.valueOf(2.5));
        for(String s : parentList){
            System.out.println(s);//output:0, 1, 2, 2.5, 3, 4
        }

        //如果你在调用了sublist返回了子list之后，如果修改了原list的大小，那么之前产生的子list将会失效，变得不可使用。报 java.util.ConcurrentModificationException
        parentList.add("undefine");
        System.out.println("=================");
        for(String s : subList){
            System.out.print(s);
        }
        System.out.println("=================");
        subList.get(0);

    }
}
